package com.mydemo.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * chatModel+chatClient+多模型共存
 */
@Configuration
public class SaaLLMConfig {

    private final String DEEPSEEK_MODEL="deepseek-v3.2-exp";
    private final String QWEN_MODEL="qwen-max";

    //chatModel 配置
    @Bean(name="deepseek")
    public ChatModel deepSeekModel(){
        String apiKey = System.getenv("AI_DASHSCOPE_API_KEY");
        System.out.println("apiKey:"+apiKey);
       return DashScopeChatModel.builder()
               .dashScopeApi(DashScopeApi.builder().apiKey(System.getenv("AI_DASHSCOPE_API_KEY")).build())
               .defaultOptions(DashScopeChatOptions.builder().withModel(DEEPSEEK_MODEL).build())
               .build();
    }

    @Bean(name="qwen")
    public ChatModel qwenModel(){
        return DashScopeChatModel.builder()
                .dashScopeApi(DashScopeApi.builder().apiKey(System.getenv("AI_DASHSCOPE_API_KEY")).build())
                .defaultOptions(DashScopeChatOptions.builder().withModel(QWEN_MODEL).build())
                .build();
    }

    //chatClient 可以使用@Resource注解
    @Bean(name="deepSeekChatClient")
    public ChatClient deepSeekChatClient(@Qualifier("deepseek") ChatModel deepSeekModel){
        return ChatClient.builder(deepSeekModel)
                .defaultOptions(ChatOptions.builder().model(DEEPSEEK_MODEL).build())
                .build();
    }

    @Bean(name="qwenChatClient")
    public ChatClient qwenChatClient(@Qualifier("qwen") ChatModel qwenModel){
        return ChatClient.builder(qwenModel)
                .defaultOptions(ChatOptions.builder().model(QWEN_MODEL).build())
                .build();
    }
}
